#include "../lib/coredataunit.hpp"
#include <cstring>

using namespace pland;

Data::Data()
{
	filled_ = false;
	header_ = NULL;
	data_ = NULL;
}

Data::Data(const Data& d)
{
	if(d.filled_ == false)
		filled_ = false;
	else
	{
		header_ = new Data_Header;
		memcpy(header_, d.header_, sizeof(Data_Header));
		data_ = new char[header_->size];
		memcpy(data_, d.data_, header_->size);
		filled_ = true;

	}
}

Data::Data(void* data,  Data_Header *header)
{
	data_ = data;
	header_ = header;
	filled_ = true;
}

Data::~Data()
{
	if(filled_)
	{
		delete[] (char*)data_;
        delete header_;
	}
}

void Data::load_data(void* data, Data_Header *header)
{
	if(filled_)
	{
		delete[] (char*)data_;
        delete header_;
	}
	filled_ = true;
	data_ = data;
	header_ = header;
}

void Data::clear()
{
	if(filled_)
	{
		delete[] (char*)data_;
        delete header_;
	}
	filled_ = false;
	data_ = NULL;
	header_ = NULL;
}

Data_Header* Data::get_header()
{
	return header_;
}

bool Data::is_inited()
{
	return filled_;
}

void* Data::get_data()
{
	return data_;
}
